<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use yii\grid\GridView;
use backend\helpers\ActionButton;
use backend\helpers\FileViewHelper;
use backend\helpers\DateTimeHelper;
use backend\models\Project;
use kartik\export\ExportMenu;

/* @var $this yii\web\View */
/* @var $model backend\models\Project */

$this->registerJs(
    "$('.js-file-exist').tooltip();",
);

$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Проекты', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;

$this->params['id'] = $model->id;

\yii\web\YiiAsset::register($this);

?>
<div class="container project-view">

    <h1 class="main-title"><?= Html::encode($this->title) ?></h1>

    <div class="row">
        <div class="col-sm-11"><?= $this->render('/project/_menu') ?></div>
        <div class="col-sm-1"><?= ActionButton::delete($model->id, 'Вы точно хотите удалить информацию о проекте?', 'deleteProject') ?></div>
    </div>
    
</div>

<div class="container-fluid contract-table-container">
    <?
        $gridColumns = [
            'own_number',
            [
                'attribute' => 'id_contractor',
                'value' => 'contractor.name_short_opf',
            ],
            'subject',
            'total_price',
            [
                'attribute' => 'date_sign',
                'format' => 'date',
            ],
        ];
        echo ExportMenu::widget([
            'dataProvider' => $contractDataProvider,
            'columns' => $gridColumns,
            'exportConfig' => [
                ExportMenu::FORMAT_HTML => false,
                ExportMenu::FORMAT_CSV => false,
                ExportMenu::FORMAT_TEXT => false,
                ExportMenu::FORMAT_EXCEL => false,
            ]
        ]);
    ?>
    <?= GridView::widget([
        'dataProvider' => $contractDataProvider,
        'tableOptions' => [
            'class' => 'table table-striped'
        ],
        'layout' => '{items}', 
        'columns' => [
            'own_number',
            //'contractor_number',
            [
                'attribute' => 'id_contractor',
                'value' => 'contractor.name_short_opf',
            ],
            'subject',
            'total_price:currency',
            [
                'attribute' => 'date_sign',
                'format' => 'date',
            ],
            //'date_sign:date',
            //'date_realize:date',
            // [
            //     'attribute' => 'date_realize',
            //     'format' => 'date',
            // ],
            [
                'attribute' => 'id_status',
                'value' => function($model) { 
                    return '<span class="badge ' . $model->status->css_style . '">' . $model->status->title . '</span>'; 
                },
                'format' => 'raw',
            ],
            [
                'label' => 'Файлы',
                'value' => function ($model) { return FileViewHelper::fileExist($model); },
                'format' => 'raw',
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'controller' => 'contract',
                'visibleButtons' =>
                [
                    'view' => Yii::$app->user->can('browseContract'),
                    'update' => Yii::$app->user->can('updateContract'),
                    'delete' => Yii::$app->user->can('deleteContract'),
                ]
            ],
        ],
    ]);?>
</div>
